﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace mozhi.smarterp.BasicData.Migrations
{
    public partial class _202503021120 : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.RenameColumn(
                name: "Address",
                table: "MozhiSupplier",
                newName: "Telephone");

            migrationBuilder.RenameColumn(
                name: "Address",
                table: "MozhiCustomer",
                newName: "Telephone");

            migrationBuilder.AddColumn<string>(
                name: "Country",
                table: "MozhiSupplier",
                type: "longtext",
                nullable: true)
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<string>(
                name: "MailAddress",
                table: "MozhiSupplier",
                type: "longtext",
                nullable: true)
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<string>(
                name: "PostalCode",
                table: "MozhiSupplier",
                type: "longtext",
                nullable: true)
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<string>(
                name: "Region",
                table: "MozhiSupplier",
                type: "longtext",
                nullable: true)
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<string>(
                name: "BarCode",
                table: "MozhiProduct",
                type: "longtext",
                nullable: true)
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<Guid>(
                name: "BasicUnitId",
                table: "MozhiProduct",
                type: "char(36)",
                nullable: false,
                defaultValue: new Guid("00000000-0000-0000-0000-000000000000"),
                collation: "ascii_general_ci");

            migrationBuilder.AddColumn<bool>(
                name: "Producible",
                table: "MozhiProduct",
                type: "tinyint(1)",
                nullable: false,
                defaultValue: false);

            migrationBuilder.AddColumn<bool>(
                name: "Purchasable",
                table: "MozhiProduct",
                type: "tinyint(1)",
                nullable: false,
                defaultValue: false);

            migrationBuilder.AddColumn<bool>(
                name: "Saleable",
                table: "MozhiProduct",
                type: "tinyint(1)",
                nullable: false,
                defaultValue: false);

            migrationBuilder.AddColumn<Guid>(
                name: "DepartmentId",
                table: "MozhiEmployee",
                type: "char(36)",
                nullable: true,
                collation: "ascii_general_ci");

            migrationBuilder.AddColumn<string>(
                name: "Country",
                table: "MozhiCustomer",
                type: "longtext",
                nullable: true)
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<string>(
                name: "MailAddress",
                table: "MozhiCustomer",
                type: "longtext",
                nullable: true)
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<string>(
                name: "PostalCode",
                table: "MozhiCustomer",
                type: "longtext",
                nullable: true)
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<string>(
                name: "Region",
                table: "MozhiCustomer",
                type: "longtext",
                nullable: true)
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "CustomerContactItem",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
                    CustomerId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
                    Name = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Telephone = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    MobilePhone = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Email = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    TenantId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_CustomerContactItem", x => x.Id);
                    table.ForeignKey(
                        name: "FK_CustomerContactItem_MozhiCustomer_CustomerId",
                        column: x => x.CustomerId,
                        principalTable: "MozhiCustomer",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "MozhiUnit",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
                    ExtraProperties = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    ConcurrencyStamp = table.Column<string>(type: "varchar(40)", maxLength: 40, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    CreationTime = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    CreatorId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"),
                    LastModificationTime = table.Column<DateTime>(type: "datetime(6)", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"),
                    Activated = table.Column<bool>(type: "tinyint(1)", nullable: false),
                    TenantId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"),
                    Code = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Name = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MozhiUnit", x => x.Id);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "SupplierContactItem",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
                    SupplierId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
                    Name = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    JobTitle = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Telephone = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    MobilePhone = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Email = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    TenantId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SupplierContactItem", x => x.Id);
                    table.ForeignKey(
                        name: "FK_SupplierContactItem_MozhiSupplier_SupplierId",
                        column: x => x.SupplierId,
                        principalTable: "MozhiSupplier",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateIndex(
                name: "IX_CustomerContactItem_CustomerId",
                table: "CustomerContactItem",
                column: "CustomerId");

            migrationBuilder.CreateIndex(
                name: "IX_SupplierContactItem_SupplierId",
                table: "SupplierContactItem",
                column: "SupplierId");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "CustomerContactItem");

            migrationBuilder.DropTable(
                name: "MozhiUnit");

            migrationBuilder.DropTable(
                name: "SupplierContactItem");

            migrationBuilder.DropColumn(
                name: "Country",
                table: "MozhiSupplier");

            migrationBuilder.DropColumn(
                name: "MailAddress",
                table: "MozhiSupplier");

            migrationBuilder.DropColumn(
                name: "PostalCode",
                table: "MozhiSupplier");

            migrationBuilder.DropColumn(
                name: "Region",
                table: "MozhiSupplier");

            migrationBuilder.DropColumn(
                name: "BarCode",
                table: "MozhiProduct");

            migrationBuilder.DropColumn(
                name: "BasicUnitId",
                table: "MozhiProduct");

            migrationBuilder.DropColumn(
                name: "Producible",
                table: "MozhiProduct");

            migrationBuilder.DropColumn(
                name: "Purchasable",
                table: "MozhiProduct");

            migrationBuilder.DropColumn(
                name: "Saleable",
                table: "MozhiProduct");

            migrationBuilder.DropColumn(
                name: "DepartmentId",
                table: "MozhiEmployee");

            migrationBuilder.DropColumn(
                name: "Country",
                table: "MozhiCustomer");

            migrationBuilder.DropColumn(
                name: "MailAddress",
                table: "MozhiCustomer");

            migrationBuilder.DropColumn(
                name: "PostalCode",
                table: "MozhiCustomer");

            migrationBuilder.DropColumn(
                name: "Region",
                table: "MozhiCustomer");

            migrationBuilder.RenameColumn(
                name: "Telephone",
                table: "MozhiSupplier",
                newName: "Address");

            migrationBuilder.RenameColumn(
                name: "Telephone",
                table: "MozhiCustomer",
                newName: "Address");
        }
    }
}
